package pers.crayon.baseprogram.util;

import lombok.experimental.UtilityClass;

import java.io.*;

/**
 * @author roamay.com
 * @since 2021/9/17 15:53
 */
@UtilityClass
public class FileUtil {


    /**
     * 根据文件路径读取文件内容
     *
     * @param fileInPath
     * @return
     * @throws IOException
     */
    public static String getFileContent(Object fileInPath) throws IOException {
        BufferedReader br = null;
        if (fileInPath == null) {
            return null;
        }
        if (fileInPath instanceof String) {
            br = new BufferedReader(new FileReader(new File((String) fileInPath)));
        } else if (fileInPath instanceof InputStream) {
            br = new BufferedReader(new InputStreamReader((InputStream) fileInPath));
        }
        String line;
        StringBuilder stringBuilder = new StringBuilder();
        while ((line = br.readLine()) != null) {
            stringBuilder.append(line);
        }
        br.close();
        return stringBuilder.toString();
    }
}
